package p.ithorns.sample.refresh;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TestController
 *
 * @author HtL
 * @date 2024/12/10 12:33
 * @since 1.0.0
 */
@RestController
@RequestMapping
@SpringBootApplication
public class TestApp {

    @Autowired
    private AppConfig config;

    @Refreshable
    @Value("#{'${app.user.value:nnn}'.toUpperCase()}")
    private String valueProp;

    private String methodValue;

    @Value("#{'${app.method:xyz}'.toLowerCase()}")
    public void setMethodValue(String v) {
        this.methodValue = v;
    }


    @Autowired
    private ApplicationContext context;

    @GetMapping("test")
    public String test() {
        return config.getName() + ":" + valueProp + ":" + config.getDebug().isEnabled() + ":" + methodValue;
    }

    public static void main(String[] args) {
//        SpringApplication.run(TestApp.class, args);

        // 手动注册CustomizeConfigContextInitializer
        SpringApplication app = new SpringApplication(TestApp.class);
        app.addInitializers(new CustomizeConfigContextInitializer());
        app.run(args);
    }

}